﻿using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;

using UI.WebControls.ControlsBase;
using BLL.Common;
using Model.Common;
namespace UI.WebControls
{
    /// <summary>
    /// UI层，页面控件基类，城市下拉
    /// </summary>
    public class CityDDL : DropDownListBase
    {
        /// <summary>
        /// 设置显示全部还是包含信息的
        /// </summary>
        public bool ShowAll = true;

        /// <summary>
        /// 默认的省份
        /// </summary>
        public int ProvinceID = 0;

        protected override void OnLoad(EventArgs e)
        {
            base.Items.Add(new ListItem("=选择城市=", "0"));
            base.OnLoad(e);
        }

        /// <summary>
        /// 重写数据绑定事件
        /// </summary>
        /// <param name="e"></param>
        protected override void OnDataBinding(EventArgs e)
        {
            this.Items.Clear();
            base.Items.Add(new ListItem("=选择城市=", "0"));
            if (ProvinceID > 0) 
            {
                IList<CityInfo> list = ShowAll ? new CityBLL().GetAllCity(ProvinceID) : new CityBLL().GetInfoCity(ProvinceID);
                foreach (CityInfo info in list)
                    base.Items.Add(new ListItem(info.CityName, info.CityID.ToString()));
            }
            base.OnDataBinding(e);
        }
    }
}
